import React from 'react';
import {Spin, Card, Button, Row, Col, Table, Form, Popconfirm, Message as msg} from 'antd';
import PropTypes from 'prop-types';
import routes from './routes';
import {FORM_OPTIONS, TABLE, DATE_FORMAT, FIXED_COLUMN_WIDTH, FORM_ROW_OPTIONS} from '../constants';
import {addApplyReport} from './api';
import {formatDateTime} from '../utils';
import VehicleSoldSelectPanel from './VehicleSoldSelectPanel';
import {vehicleNature, importInfo, occurCondition, problemSeverity, replyForm} from '../Enum';
import TextInput from 'Shared/components/TextInput';
import SearchInput from 'Shared/components/SearchInput';
import ProductCategorySelectPanel from './ProductCategorySelectPanel';
import WrappedDatePicker from '../common/WrappedDatePicker';
import InputAmount from '../common/InputAmount';
import PartSelectPanel from './PartSelectPanel';
import {injectIntl, language} from './intl';
import WrappedSelect from '../common/WrappedSelect';
import LocalizeInputNumber from '../common/LocalizeInputNumber';
import styles from './style.css';
import Return from '../common/Return';
import {newOrUpdateOrderValidator} from './validator';
const FormItem = Form.Item;
const today = new Date();

const vehicleNatureToList = vehicleNature.toList(language);
const importInfoToList = importInfo.toList(language);
const occurConditionToList = occurCondition.toList(language);
const problemSeverityToList = problemSeverity.toList(language);
const replyFormToList = replyForm.toList(language);
class AddPanel extends React.PureComponent {
    state = {
        loading: false,
        hasOperat: false,
        isValidate: false,
        showVehicleSoldSelectPanel: false,
        showProductCategorySelectPanel: false,
        showPartSelectPanel: false,
        data: {},
        details: [],
    }
    componentWillUnmount() {
        this.isunmount = true;
    }
    onChange = (value, name) => {
        const data = Object.assign({}, this.state.data, {
            [name]: value
        });
        this.setState({
            data,
            hasOperat: true
        });
    }
    onClickOkOnPopconfirm = () => {
        this.props.onCancel();
    }
    onSubmit = () => {
        const data = this.state.data;
        const details = this.state.details;
        const isValid = newOrUpdateOrderValidator(data, details);
        if(!isValid) {
            this.setState({
                isValidate: true
            });
            return;
        }
        const condition = {
            brandId: data.brandId,
            serviceEngineer: data.serviceEngineer,
            qualityEngineer: data.qualityEngineer,
            productCategoryId: data.productCategoryId,
            vehicleNature: data.vehicleNature,
            frequency: data.frequency,
            faultPartCode: data.faultPartCode,
            customerComplainQty: data.customerComplainQty,
            outRescueQty: data.outRescueQty,
            specialCompensateQty: data.specialCompensateQty,
            carReturnQty: data.carReturnQty,
            marketValueFactor: data.marketValueFactor,
            warranty: data.warranty,
            importInfo: data.importInfo,
            causePartId: data.causePartId,
            faultyPartBatch: data.faultyPartBatch,
            softwareVersionNumber: data.softwareVersionNumber,
            failureRatio: data.failureRatio,
            iPTV: data.iPTV,
            occurCondition: data.occurCondition,
            issueRoadConditions: data.issueRoadConditions,
            issueWorkConditions: data.issueWorkConditions,
            driveHabits: data.driveHabits,
            useEnvironment: data.useEnvironment,
            problemDescribe: data.problemDescribe,
            servicePropose: data.servicePropose,
            factoryAdvice: data.factoryAdvice,
            problemSeverity: data.problemSeverity,
            replyForm: data.replyForm,
            details: details.map(v => ({
                id: v.id,
                faultDescription: v.faultDescription,
                inspectionProcess: v.inspectionProcess,
                dealResult: v.dealResult,
                supplierCode: v.supplierCode,
                repairDate: v.repairDate,
                mileage: v.mileage,
                claimPrice: v.claimPrice,
                subDealerCode: v.subDealerCode,
                subDealerName: v.subDealerName,
            })),
        };
        this.setState({loading: true});
        addApplyReport(condition).then(res => {
            if(res.ok)
                this.props.successReturn();
            if(!this.isunmount)
                this.setState({loading: false});
        });
    }
    onClickSearchProductCategoryBtn = () => {
        this.setState({
            showProductCategorySelectPanel: true
        });
    }
    onCloseProductCategorySelectPanel = () => {
        this.setState({showProductCategorySelectPanel: false});
    }
    onSelectProductCategory = records => {
        this.setState({
            data: Object.assign({}, this.state.data, {
                productCategoryId: records.id,
                productCategoryCode: records.code,
                productCategoryName: records.name,
            }),
            hasOperat: true,
            showProductCategorySelectPanel: false
        });
    }
    onClickSearchPartBtn = () => {
        this.setState({
            showPartSelectPanel: true
        });
    }
    onClosePartSelectPanel = () => {
        this.setState({showPartSelectPanel: false});
    }
    onSelectPart = records => {
        const details = this.state.details || [];
        const temp = details.map(p =>
            Object.assign({}, p, {
                causePartCode: records.code,
                causePartName: records.name,
            })
        );
        this.setState({
            data: Object.assign({}, this.state.data, {
                causePartId: records.id,
                causePartCode: records.code,
                causePartName: records.name,
            }),
            details: temp,
            hasOperat: true,
            showPartSelectPanel: false
        });
    }
    onClickAddDetailBtn = () => {
        if(!this.state.data.productCategoryId)
            return msg.warn(this.props.intl.formatMessage({
                id: 'newPanel.message.productCategoryId',
                defaultMessage: '请先选择车型'
            }));
        this.setState({
            showVehicleSoldSelectPanel: !this.state.showVehicleSoldSelectPanel
        });
    }
    onSelectVehicleSolds = value => {
        const details = this.state.details;
        const data = this.state.data;
        value.map(p => {
            const detail = this.state.details.find(d => d.id === p.id);
            if(!detail) {
                const detail = {
                    id: p.id,
                    vin: p.vin,
                    productCategoryCode: p.productCategoryCode,
                    productCategoryName: p.productCategoryName,
                    engineCode: p.engineCode,
                    transmissionSn: p.transmissionSn,
                    productionDate: p.productionDate,
                    saleDate: p.saleDate,
                    causePartCode: data.causePartCode,
                    causePartName: data.causePartName,
                };
                details.push(detail);
            }
            return p;
        });
        this.setState({
            showVehicleSoldSelectPanel: false,
            hasOperat: true,
            details
        });
    }
    onDeleteAll = () => {
        this.setState({
            details: [],
            hasOperat: true
        });
    }
    onDeleteDetail = e => {
        const id = e.target.dataset.id;
        const details = this.state.details.filter(p => p.id !== id);
        this.setState({
            details,
            hasOperat: true
        });
    }
    onChangeAll = (value, id, e) => {
        const details = this.state.details || [];
        const name = e.target.name;
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    [name]: value
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onChangeTime = (value, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    repairDate: value
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onUpdateMileage = (mileage, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    mileage,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onUpdateClaimPrice = (claimPrice, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    claimPrice,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    render() {
        const {formatMessage} = this.props.intl;
        const {data, details, isValidate, loading} = this.state;
        const {brands, dealer} = this.props.initEnumData;
        const {isDealerUser} = this.props;
        if(brands.length === 1 && !this.props.id) {
            data.brandId = brands[0].value;
            data.brandName = brands[0].text;
        }
        const columns = [{
            title: formatMessage({
                id: 'addPanel.column.vin',
                defaultMessage: 'VIN'
            }),
            dataIndex: 'vin',
        }, {
            title: formatMessage({
                id: 'addPanel.column.productCategoryCode',
                defaultMessage: '车型编号'
            }),
            dataIndex: 'productCategoryCode',
        }, {
            title: formatMessage({
                id: 'addPanel.column.productCategoryName',
                defaultMessage: '车型名称'
            }),
            dataIndex: 'productCategoryName',
        }, {
            title: formatMessage({
                id: 'addPanel.column.engineCode',
                defaultMessage: '发动机号'
            }),
            dataIndex: 'engineCode',
        }, {
            title: formatMessage({
                id: 'addPanel.column.transmissionSn',
                defaultMessage: '变速箱号'
            }),
            dataIndex: 'transmissionSn',
        }, {
            title: formatMessage({
                id: 'addPanel.column.productionDate',
                defaultMessage: '生产日期'
            }),
            dataIndex: 'productionDate',
            render: text => formatDateTime(text, DATE_FORMAT)
        }, {
            title: formatMessage({
                id: 'addPanel.column.saleDate',
                defaultMessage: '购车日期'
            }),
            dataIndex: 'saleDate',
            render: text => formatDateTime(text, DATE_FORMAT)

        }, {
            title: formatMessage({
                id: 'addPanel.column.causePartCode',
                defaultMessage: '备件编号'
            }),
            dataIndex: 'causePartCode',
        }, {
            title: formatMessage({
                id: 'addPanel.column.causePartName',
                defaultMessage: '备件名称'
            }),
            dataIndex: 'causePartName',
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.faultDescription',
                defaultMessage: '故障描述'
            })}</span>,
            dataIndex: 'faultDescription',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="faultDescription"
                            value={text}
                            onBlur={this.onChangeAll} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.inspectionProcess',
                defaultMessage: '检查过程'
            })}</span>,
            dataIndex: 'inspectionProcess',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="inspectionProcess"
                            value={text}
                            onBlur={this.onChangeAll} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.dealResult',
                defaultMessage: '处理结果'
            })}</span>,
            dataIndex: 'dealResult',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="dealResult"
                            value={text}
                            onBlur={this.onChangeAll} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.supplierCode',
                defaultMessage: '供应商代码'
            })}</span>,
            dataIndex: 'supplierCode',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="supplierCode"
                            value={text}
                            onBlur={this.onChangeAll} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.repairDate',
                defaultMessage: '修理日期'
            })}</span>,
            dataIndex: 'repairDate',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <WrappedDatePicker
                            name={record.id}
                            value={text}
                            onChange={this.onChangeTime} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.mileage',
                defaultMessage: '行驶里程'
            })}</span>,
            dataIndex: 'mileage',
            render: (text, record) => {
                const validate = (!text || text === undefined) && text !== 0 ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <LocalizeInputNumber
                            id={record.id}
                            value={text}
                            onBlur={this.onUpdateMileage} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.claimPrice',
                defaultMessage: '索赔金额'
            })}</span>,
            dataIndex: 'claimPrice',
            render: (text, record) => {
                const validate = (!text || text === undefined) && text !== 0 ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <InputAmount
                            id={record.id}
                            value={text}
                            onBlur={this.onUpdateClaimPrice} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.subDealerCode',
                defaultMessage: '经销商编号'
            })}</span>,
            dataIndex: 'subDealerCode',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="subDealerCode"
                            value={text}
                            onBlur={this.onChangeAll} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.subDealerName',
                defaultMessage: '经销商名称'
            })}</span>,
            dataIndex: 'subDealerName',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="subDealerName"
                            value={text}
                            onBlur={this.onChangeAll} />
                    </FormItem>
                );
            }
        }, {
            title: details.length > 0
                ? (
                    <Popconfirm placement="topRight" title={formatMessage({
                        id: 'addPanel.validation.isDelete',
                        defaultMessage: '是否确认全部删除？'
                    })} onConfirm={this.onDeleteAll} >
                        <a>{formatMessage({
                            id: 'addPanel.validation.clear',
                            defaultMessage: '清空'
                        })}</a>
                    </Popconfirm>
                )
                : null,
            dataIndex: 'id',
            fixed: 'right',
            width: FIXED_COLUMN_WIDTH,
            render: text => <a data-id={text} onClick={this.onDeleteDetail}>{formatMessage({
                id: 'addPanel.validation.delete',
                defaultMessage: '删除'
            })}</a>
        }];
        return (
            <div className="form-standard">
                <Spin spinning={this.state.loading}>
                    <Card title={formatMessage({
                        id: 'addPanel.column.common',
                        defaultMessage: '质量反馈信息'
                    })}>
                        <Form>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.code',
                                        defaultMessage: '编号'
                                    })}{...FORM_OPTIONS.item}>
                                        <span className="value-font">{formatMessage({
                                            id: 'addPanel.value.defalut',
                                            defaultMessage: '尚未生成'
                                        })}</span>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.today',
                                        defaultMessage: '发起日期'
                                    })}{...FORM_OPTIONS.item}>
                                        {formatDateTime(today, DATE_FORMAT)}
                                    </FormItem>
                                </Col>
                                { (!isDealerUser || dealer.dealerId) && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'addPanel.form.dealerId',
                                        defaultMessage: '总代'
                                    })}{...FORM_OPTIONS.item}>
                                        ({dealer.dealerCode}){dealer.dealerName}
                                    </FormItem>
                                </Col>}
                                {brands.length !== 1 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.brandName',
                                        defaultMessage: '品牌'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.brandId ? 'error' : null} required>
                                        <WrappedSelect
                                            name="brandId"
                                            value={data.brandId}
                                            options={brands}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.serviceEngineer',
                                        defaultMessage: '售后服务工程师'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.serviceEngineer ? 'error' : null} required>
                                        <TextInput
                                            name="serviceEngineer"
                                            value={data.serviceEngineer}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.qualityEngineer',
                                        defaultMessage: '售后质量工程师'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.qualityEngineer ? 'error' : null} required>
                                        <TextInput
                                            name="qualityEngineer"
                                            value={data.qualityEngineer}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.data.productCategoryId',
                                        defaultMessage: '车型'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.productCategoryId ? 'error' : null} required>
                                        <SearchInput
                                            disabled={true}
                                            value={data.productCategoryCode === undefined ? '' : `(${data.productCategoryCode})${data.productCategoryName}`}
                                            onClickSearchBtn={() => this.onClickSearchProductCategoryBtn()} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.vehicleNature',
                                        defaultMessage: '车辆性质'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.vehicleNature ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="vehicleNature"
                                            options={vehicleNatureToList}
                                            value={data.vehicleNature}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.frequency',
                                        defaultMessage: '频次'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.frequency ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="frequency"
                                            value={data.frequency}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.region',
                                        defaultMessage: '区域'
                                    })} {...FORM_OPTIONS.item}>
                                        {dealer.region}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.country',
                                        defaultMessage: '国家'
                                    })} {...FORM_OPTIONS.item}>
                                        {dealer.country}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.faultPartCode',
                                        defaultMessage: '故障件代码'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.faultPartCode ? 'error' : null} required>
                                        <TextInput
                                            name="faultPartCode"
                                            value={data.faultPartCode}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.customerComplainQty',
                                        defaultMessage: '客户抱怨数'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.customerComplainQty ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="customerComplainQty"
                                            value={data.customerComplainQty}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.outRescueQty',
                                        defaultMessage: '外出救援数'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.outRescueQty ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="outRescueQty"
                                            value={data.outRescueQty}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.specialCompensateQty',
                                        defaultMessage: '客户特殊补偿数'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.specialCompensateQty ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="specialCompensateQty"
                                            value={data.specialCompensateQty}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.carReturnQty',
                                        defaultMessage: '退换车数'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.carReturnQty ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="carReturnQty"
                                            value={data.carReturnQty}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.marketValueFactor',
                                        defaultMessage: '市场评价系数'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.marketValueFactor ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="marketValueFactor"
                                            value={data.marketValueFactor}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.warranty',
                                        defaultMessage: '索赔数'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.warranty ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="warranty"
                                            value={data.warranty}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.importInfo',
                                        defaultMessage: '进口信息'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.importInfo ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="importInfo"
                                            options={importInfoToList}
                                            value={data.importInfo}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.causePartId',
                                        defaultMessage: '备件'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.causePartId ? 'error' : null} required>
                                        <SearchInput
                                            disabled={true}
                                            value={data.causePartCode === undefined ? '' : `(${data.causePartCode})${data.causePartName}`}
                                            onClickSearchBtn={() => this.onClickSearchPartBtn()} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.faultyPartBatch',
                                        defaultMessage: '故障件生产批次'
                                    })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="faultyPartBatch"
                                            value={data.faultyPartBatch}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.softwareVersionNumber',
                                        defaultMessage: '软件版本号'
                                    })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="softwareVersionNumber"
                                            value={data.softwareVersionNumber}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.failureRatio',
                                        defaultMessage: '故障比例'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.failureRatio ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="failureRatio"
                                            value={data.failureRatio}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.iPTV',
                                        defaultMessage: 'IPTV'
                                    })} {...FORM_OPTIONS.item}>
                                        <LocalizeInputNumber
                                            name="iPTV"
                                            value={data.iPTV}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.occurCondition',
                                        defaultMessage: '发生条件'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.occurCondition ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="occurCondition"
                                            options={occurConditionToList}
                                            value={data.occurCondition}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.issueRoadConditions',
                                        defaultMessage: '问题出现路况'
                                    })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="issueRoadConditions"
                                            value={data.issueRoadConditions}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.issueWorkConditions',
                                        defaultMessage: '问题出现工况'
                                    })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="issueWorkConditions"
                                            value={data.issueWorkConditions}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.driveHabits',
                                        defaultMessage: '驾驶习惯'
                                    })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="driveHabits"
                                            value={data.driveHabits}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.useEnvironment',
                                        defaultMessage: '使用环境'
                                    })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="useEnvironment"
                                            value={data.useEnvironment}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.problemSeverity',
                                        defaultMessage: '问题严重度'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.problemSeverity ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="problemSeverity"
                                            options={problemSeverityToList}
                                            value={data.problemSeverity}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.replyForm',
                                        defaultMessage: '回复形式'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.replyForm ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="replyForm"
                                            options={replyFormToList}
                                            value={data.replyForm}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row className="row-margin">
                                <Col>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.problemDescribe',
                                        defaultMessage: '问题描述'
                                    })} {...FORM_ROW_OPTIONS.item} validateStatus={isValidate && !data.problemDescribe ? 'error' : null} required>
                                        <TextInput
                                            name="problemDescribe"
                                            type="textarea"
                                            value={data.problemDescribe}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row className="row-margin">
                                <Col>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.factoryAdvice',
                                        defaultMessage: '工厂处理和建议'
                                    })} {...FORM_ROW_OPTIONS.item}>
                                        <TextInput
                                            name="factoryAdvice"
                                            type="textarea"
                                            value={data.factoryAdvice}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row className="row-margin">
                                <Col>
                                    <FormItem className={styles.multiLabel} label={formatMessage({
                                        id: 'addPanel.operation.servicePropose',
                                        defaultMessage: '服务站处理情况及建议'
                                    })} {...FORM_ROW_OPTIONS.item} validateStatus={isValidate && !data.servicePropose ? 'error' : null} required>
                                        <TextInput
                                            name="servicePropose"
                                            type="textarea"
                                            value={data.servicePropose}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </Card>
                    <Card
                        title={formatMessage({
                            id: 'addPanel.operation.detail',
                            defaultMessage: '质量反馈清单'
                        })} extra={<div>
                            <Button
                                size="small"
                                onClick={this.onClickAddDetailBtn}>
                                {formatMessage({
                                    id: 'addPanel.btn.add',
                                    defaultMessage: '增加清单'
                                })}
                            </Button>
                        </div>}>
                        <Table
                            className="white-space-nowrap"
                            columns={columns}
                            rowKey="id"
                            pagination={false}
                            dataSource={details}
                            {...TABLE} />
                    </Card>
                    <Card className={styles.optionBtn}>
                        <Button
                            type="primary"
                            onClick={this.onSubmit}
                            loading={loading}>
                            {formatMessage({
                                id: 'addPanel.operation.onSubmit',
                                defaultMessage: '保存'
                            })}
                        </Button>
                    </Card>
                </Spin>
                {
                    this.state.showProductCategorySelectPanel &&
                    <ProductCategorySelectPanel
                        selectKey={data.productCategoryId}
                        onCancel={this.onCloseProductCategorySelectPanel}
                        onSelect={this.onSelectProductCategory} />
                }
                {
                    this.state.showPartSelectPanel &&
                    <PartSelectPanel
                        dealerId={dealer.dealerId}
                        brandId={data.brandId}
                        selectKey={data.causePartId}
                        onCancel={this.onClosePartSelectPanel}
                        onSelect={this.onSelectPart} />
                }
                {
                    this.state.showVehicleSoldSelectPanel && <VehicleSoldSelectPanel
                        selectKey={details.id}
                        code={this.state.data.productCategoryCode}
                        onCancel={this.onClickAddDetailBtn}
                        onSelect={this.onSelectVehicleSolds} />
                }
                <div className="page-toolbar">
                    <Return
                        disabled={this.state.loading}
                        onConfirm={this.onClickOkOnPopconfirm}
                        showWarning={this.state.hasOperat} />
                </div>
            </div>
        );
    }
}

AddPanel.propTypes = {
    successReturn: PropTypes.func.isRequired,
    onCancel: PropTypes.func.isRequired,
    onSelect: PropTypes.func.isRequired,
    history: PropTypes.object,
    id: PropTypes.string,
    intl: PropTypes.object,
    isDealerUser: PropTypes.bool,
};

import {connect} from 'react-redux';
import {
    tableSearch,
    saveQueryDealer
} from './actions';
import {createSelector} from 'reselect';

const getinitEnumData = createSelector(
    state => state.getIn(['page', 'domainData', 'init']),
    init => {
        const initData = init.toJS();
        const brands = initData.brands ? initData.brands.map(item => ({
            text: `(${item.code})${item.name}`,
            value: item.id
        })) : [];
        const dealer = initData.dealer ? initData.dealer : {};
        return {
            brands,
            dealer
        };
    }
);
const mapStateToProps = state => ({
    initEnumData: getinitEnumData(state),
    isDealerUser: state.getIn((['page', 'domainData', 'init', 'isDealerUser'])),
});
const mapDispatchToProps = (dispatch, props) => ({
    onSelect: data => dispatch(saveQueryDealer(data)),
    successReturn: () => {
        dispatch(tableSearch());
        props.history.push(routes.query.url());
    },
    onCancel: () => {
        props.history.push(routes.query.url());
    },
});
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(AddPanel));
